package com.app.ctrl;

import com.app.mapper.TestkeyMapper;
import com.app.pojo.Testkey;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
public class TestCtrl {

    @Autowired
    private TestkeyMapper testkeyMapper;

    @RequestMapping("/")
    public void test() {
        System.out.println("成功接收请求");
    }

    @RequestMapping("/testkey")
    public void testkey() {
        //查询testkey里面的所有信息
        List<Testkey> testKeys = testkeyMapper.selectList(null);
        for (Testkey k : testKeys) {
            System.out.println(k);
        }


    }

    @RequestMapping("/testkey2")
    public void testkey2(Testkey key) {
        //添加testkey的信息
        int insert = testkeyMapper.insert(key);
        System.out.println("成功插入数据" + insert);
        }

    @RequestMapping("/testkey3")
    public void testkey3() {
        Page<Testkey> page = new Page<>();
        page.setSize(5l);
        page.setCurrent(3l);
        QueryWrapper<Testkey> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("key1","1");
        Page<Testkey> testkeyPage = testkeyMapper.selectPage(page,null);
        List<Testkey> list = testkeyPage.getRecords();
        for (Testkey key : list) {
            System.out.println(key);

        }
        System.out.println("---------------------------------------");
        System.err.println("当前第几页：" + testkeyPage.getCurrent());
        System.err.println("每页多少条：" + testkeyPage.getSize());
        System.err.println("总共的条数：" + testkeyPage.getTotal());



    }
}

